﻿
using System.Collections.ObjectModel;
using Lucy.Editor.Framework;

namespace Lucy.Editor.ViewModels
{
    class ProjectViewModel : ViewModel
    {
        private readonly ObservableCollection<DocumentContentViewModel> _documents;
        public ReadOnlyObservableCollection<DocumentContentViewModel> Documents {get {return new ReadOnlyObservableCollection<DocumentContentViewModel>(_documents);}}

        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    FirePropertyChanged("Name");
                }
            }
        }

        public TreeViewItemViewModel RootAssetTreeViewItem { get; private set; }
        public TreeViewItemViewModel RootProjectTreeViewItem { get; private set; }

        public ProjectViewModel()
        {
            RootAssetTreeViewItem = new TreeViewItemViewModel();
            RootProjectTreeViewItem = new TreeViewItemViewModel();
            _documents = new ObservableCollection<DocumentContentViewModel>();
        }

        public void OpenDocument(DocumentContentViewModel contentViewModel)
        {
            if (!_documents.Contains(contentViewModel))
                _documents.Add(contentViewModel);   

            contentViewModel.IsSelected = true;
        }

        public void CloseDocument(DocumentContentViewModel contentViewModel)
        {
            _documents.Remove(contentViewModel);
        }
    }
}
